﻿namespace UnityEngine
{
    using System;
    using System.Reflection;
    using System.Security;

    public sealed class Security
    {
        private static MethodInfo GetUnityCrossDomainHelperMethod(string methodname)
        {
            System.Type type = Types.GetType("UnityEngine.UnityCrossDomainHelper", "CrossDomainPolicyParser, Version=1.0.0.0, Culture=neutral");
            if (type == null)
            {
                throw new SecurityException("Cant find type UnityCrossDomainHelper");
            }
            MethodInfo method = type.GetMethod(methodname);
            if (method == null)
            {
                throw new SecurityException("Cant find " + methodname);
            }
            return method;
        }

        public static bool PrefetchSocketPolicy(string ip, int atPort)
        {
            int timeout = 0xbb8;
            return PrefetchSocketPolicy(ip, atPort, timeout);
        }

        public static bool PrefetchSocketPolicy(string ip, int atPort, int timeout)
        {
            object[] parameters = new object[] { ip, atPort, timeout };
            return (bool) GetUnityCrossDomainHelperMethod("PrefetchSocketPolicy").Invoke(null, parameters);
        }
    }
}

